package rapier.sso.core.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 
 * </p>
 *
 * @author chenkw
 * @since 2020-10-20
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("t_db_sso_app")
@ApiModel(value = "TDbSsoAppEntity对象", description = "")
public class TDbSsoAppEntity implements Serializable {

	private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "ID")
	private Long id;

	@ApiModelProperty(value = "名称")
	private String name;

	@ApiModelProperty(value = "登录页(有自定义页面需要必填)")
	private String loginPath;

	@ApiModelProperty(value = "域名")
	private String domain;

	@ApiModelProperty(value = "基础URL")
	private String baseUrl;

	@ApiModelProperty(value = "秘钥")
	private String secretKey;

	@ApiModelProperty(value = "返回用户格式(JSON)")
	private String userJson;

	@ApiModelProperty(value = "状态(-1 冻结)")
	private Integer status;

	@ApiModelProperty(value = "创建时间")
	@TableField(fill = FieldFill.INSERT)
	private Date createTime;

	@ApiModelProperty(value = "更新时间")
	@TableField(fill = FieldFill.INSERT_UPDATE)
	private Date updateTime;

	/**
	 * 权限
	 */
	@TableField(exist = false)
	private List<TDbSsoAuthEntity> auths = new ArrayList<TDbSsoAuthEntity>();

	public boolean hashAuth(String servletPath) {
		for(TDbSsoAuthEntity index : auths) {
			if(index.getAuthPath().equals(servletPath)) {
				return true;
			}
		}
		return false;
	}
}
